package Servlet;

import DAO.DAOFactory;
import DAO.PackageDAO;
import javabean.Package;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/Subpackage")
public class SubpackageServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        PackageDAO packageDAO= (PackageDAO) DAOFactory.getPackageDAOInstance();
        List<Package> packageList = null;
        try {
            packageList = packageDAO.getAllPackages();
            req.setAttribute("packageList", packageList);
            req.getRequestDispatcher("Package_Subscription.jsp").forward(req, resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}